{extend name="public/base" /}
{block name="content"}
<div class="x-nav">
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form-item">
            <label class="layui-form-label">条件搜索：</label>
            <div class="layui-input-inline">
                <select id="condition" name="condition" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="id">编号</option>
                    <option value="username">用户昵称</option>
                    <option value="start_time">开始时间</option>
                    <option value="end_time">结束时间</option>
                </select>
            </div>
            <div class="layui-inline">
                <input class="layui-input" name="content" id="content" autocomplete="off" placeholder="请输入搜索内容">
            </div>
            <button class="layui-btn layui-btn-normal" id="btnSearch"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon"></i>全部删除</button>
    </xblock>
    <table id="demo" lay-filter="test"></table>

    <!-- 行操作  -->

</div>
{/block}
{block name="js"}
<script>
    layui.use('table', function(){
        var $ = layui.jquery;
        var table = layui.table;

        //第一个实例
        table.render({
            elem: '#demo'
            ,url: '{:url("admin/excels/getExcelDatas")}' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: '编号', sort: true, fixed: 'left'}
                ,{field: 'username', title: '姓名',sort: true}
                ,{field: 'start_time', title: '开始时间', sort: true}
                ,{field: 'end_time', title: '结束时间',sort: true,}
                ,{field: 'time_count', title: '小时数',align: 'center',sort: true}
                ,{field: 'cost', title: '花费金额',align: 'center',sort: true}
            ]]
            ,id: 'idTest' //搜索容器id
        });

        //搜索
        $('#btnSearch').click(function () {
            // layer.alert($('#condition').val()+$('#content').val());
            table.reload('idTest', {
                where: { //设定异步数据接口的额外参数，任意设
                    condition: $('#condition').val(),
                    content: $('#content').val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //删除
        $('#delAll').click(function () {
            layer.confirm('确定删除吗？', {
                title: '提示',
                icon: 3
            }, function (index) {
                layer.close(index);

                $.ajax({
                    url: "{:url('admin/excels/del')}",
                    type: "post",
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg(res.msg, {
                                icon: 6,
                                time: 2000,
                            }, function () {
                                location.href = res.url;
                            });
                        }else {
                            layer.open({
                                title: '提示',
                                content: res.msg,
                                icon: 5,
                                anim: 6
                            });
                        }
                    }
                });

            });

        });

    });
</script>
{/block}